package report

import (
	"nspel/entity"
	"nspel/util"
	"strconv"
	"time"
)

type Primary struct {
	SchoolInfo        schoolInfo       `json:"SchoolInfo"`
	StudentNum        studentNum       `json:"StudentNum"`
	EachScoreInfo     eachScoreInfo    `json:"EachScoreInfo"`
	SchoolScoresInfo  schoolScoresInfo `json:"SchoolScoresInfo"`
	Height            item1            `json:"Shengao"`
	Weight            item1            `json:"Tizhong"`
	BodyMassIndex     item2            `json:"BMI"`
	BodyFat           item3            `json:"Tizhifang"`
	VitalCapacity     item4            `json:"Feihuoliang"`
	FiftyMeter        item4            `json:"Fiftymeter"`
	SitAndReach       item4            `json:"Zuolitiqianqu"`
	OneMinuteSkipping item4            `json:"Yifenzhongtiao"`
	OneMinuteSitUps   item4            `json:"Yangwoqizuo"`
	ShuttleRun        item4            `json:"Fiftymeter8"`
	Grip              item4            `json:"Woli"`
	ReactionSpeed     item4            `json:"Fanyingsudu"`
	VerticalJump      item4            `json:"Yuandizhongtiao"`
	BalanceAbility    item4            `json:"Pinghengnengli"`
}

func (primary *Primary) Init(school *entity.School, measurementDate time.Time) (err error) {
	primary.SchoolInfo.Area, err = util.GetCityAreaName(school.ProvinceId, school.CityId, school.AreaId)
	if err != nil {
		return err
	}
	primary.SchoolInfo.Name = school.Name
	primary.SchoolInfo.SchoolType = 1
	primary.SchoolInfo.Year = strconv.Itoa(measurementDate.Year())
	primary.StudentNum.IndexName = []string{"一年级", "二年级", "三年级", "四年级", "五年级", "六年级"}
	primary.StudentNum.EachInfo = make([]studentNumEachInfo, 6)
	primary.SchoolScoresInfo.Boy = make([]float64, 4)
	primary.SchoolScoresInfo.Girl = make([]float64, 4)
	primary.SchoolScoresInfo.Avg = make([]float64, 4)
	primary.Height.IndexName = []string{"一年级", "二年级", "三年级", "四年级", "五年级", "六年级"}
	primary.Height.EachInfo = make([]item1EachInfo, 6)
	primary.Weight.IndexName = []string{"一年级", "二年级", "三年级", "四年级", "五年级", "六年级"}
	primary.Weight.EachInfo = make([]item1EachInfo, 6)
	primary.BodyMassIndex.IndexName = []string{"一年级", "二年级", "三年级", "四年级", "五年级", "六年级", "平均"}
	primary.BodyMassIndex.EachInfo = make([]item2EachInfo, 7)
	primary.BodyFat.IndexName = []string{"一年级", "二年级", "三年级", "四年级", "五年级", "六年级", "平均"}
	primary.BodyFat.EachInfo = make([]item3EachInfo, 7)
	primary.VitalCapacity.IndexName = []string{"一年级", "二年级", "三年级", "四年级", "五年级", "六年级", "平均"}
	primary.VitalCapacity.EachInfo = make([]item4EachInfo, 7)
	primary.FiftyMeter.IndexName = []string{"一年级", "二年级", "三年级", "四年级", "五年级", "六年级", "平均"}
	primary.FiftyMeter.EachInfo = make([]item4EachInfo, 7)
	primary.SitAndReach.IndexName = []string{"一年级", "二年级", "三年级", "四年级", "五年级", "六年级", "平均"}
	primary.SitAndReach.EachInfo = make([]item4EachInfo, 7)
	primary.OneMinuteSkipping.IndexName = []string{"一年级", "二年级", "三年级", "四年级", "五年级", "六年级", "平均"}
	primary.OneMinuteSkipping.EachInfo = make([]item4EachInfo, 7)
	primary.OneMinuteSitUps.IndexName = []string{"三年级", "四年级", "五年级", "六年级", "平均"}
	primary.OneMinuteSitUps.EachInfo = make([]item4EachInfo, 5)
	primary.ShuttleRun.IndexName = []string{"五年级", "六年级", "平均"}
	primary.ShuttleRun.EachInfo = make([]item4EachInfo, 3)
	primary.Grip.IndexName = []string{"一年级", "二年级", "三年级", "四年级", "五年级", "六年级", "平均"}
	primary.Grip.EachInfo = make([]item4EachInfo, 7)
	primary.ReactionSpeed.IndexName = []string{"一年级", "二年级", "三年级", "四年级", "五年级", "六年级", "平均"}
	primary.ReactionSpeed.EachInfo = make([]item4EachInfo, 7)
	primary.VerticalJump.IndexName = []string{"三年级", "四年级", "五年级", "六年级", "平均"}
	primary.VerticalJump.EachInfo = make([]item4EachInfo, 5)
	primary.BalanceAbility.IndexName = []string{"一年级", "二年级", "三年级", "四年级", "五年级", "六年级", "平均"}
	primary.BalanceAbility.EachInfo = make([]item4EachInfo, 7)
	return nil
}

type High struct {
	SchoolInfo       schoolInfo       `json:"SchoolInfo"`
	StudentNum       studentNum       `json:"StudentNum"`
	EachScoreInfo    eachScoreInfo    `json:"EachScoreInfo"`
	SchoolScoresInfo schoolScoresInfo `json:"SchoolScoresInfo"`
	Height           item1            `json:"Shengao"`
	Weight           item1            `json:"Tizhong"`
	BodyMassIndex    item2            `json:"BMI"`
	BodyFat          item3            `json:"Tizhifang"`
	VitalCapacity    item4            `json:"Feihuoliang"`
	FiftyMeter       item4            `json:"Fiftymeter"`
	SitAndReach      item4            `json:"Zuolitiqianqu"`
	OneMinuteSitUps  item4            `json:"Yangwoqizuo"`
	StandingLongJump item4            `json:"Lidingtiaoyuan"`
	EnduranceRun     item4            `json:"Naili"`
	Grip             item4            `json:"Woli"`
	ReactionSpeed    item4            `json:"Fanyingsudu"`
	VerticalJump     item4            `json:"Yuandizhongtiao"`
	BalanceAbility   item4            `json:"Pinghengnengli"`
}

func (high *High) JuniorInit(school *entity.School, measurementDate time.Time) (err error) {
	high.SchoolInfo.Area, err = util.GetCityAreaName(school.ProvinceId, school.CityId, school.AreaId)
	if err != nil {
		return err
	}
	high.SchoolInfo.Name = school.Name
	high.SchoolInfo.SchoolType = 2
	high.SchoolInfo.Year = strconv.Itoa(measurementDate.Year())
	high.StudentNum.IndexName = []string{"初一", "初二", "初三"}
	high.StudentNum.EachInfo = make([]studentNumEachInfo, 3)
	high.SchoolScoresInfo.Boy = make([]float64, 4)
	high.SchoolScoresInfo.Girl = make([]float64, 4)
	high.SchoolScoresInfo.Avg = make([]float64, 4)
	high.Height.IndexName = []string{"初一", "初二", "初三"}
	high.Height.EachInfo = make([]item1EachInfo, 3)
	high.Weight.IndexName = []string{"初一", "初二", "初三"}
	high.Weight.EachInfo = make([]item1EachInfo, 3)
	high.BodyMassIndex.IndexName = []string{"初一", "初二", "初三", "平均"}
	high.BodyMassIndex.EachInfo = make([]item2EachInfo, 4)
	high.BodyFat.IndexName = []string{"初一", "初二", "初三", "平均"}
	high.BodyFat.EachInfo = make([]item3EachInfo, 4)
	high.VitalCapacity.IndexName = []string{"初一", "初二", "初三", "平均"}
	high.VitalCapacity.EachInfo = make([]item4EachInfo, 4)
	high.FiftyMeter.IndexName = []string{"初一", "初二", "初三", "平均"}
	high.FiftyMeter.EachInfo = make([]item4EachInfo, 4)
	high.SitAndReach.IndexName = []string{"初一", "初二", "初三", "平均"}
	high.SitAndReach.EachInfo = make([]item4EachInfo, 4)
	high.StandingLongJump.IndexName = []string{"初一", "初二", "初三", "平均"}
	high.StandingLongJump.EachInfo = make([]item4EachInfo, 4)
	high.OneMinuteSitUps.IndexName = []string{"初一", "初二", "初三", "平均"}
	high.OneMinuteSitUps.EachInfo = make([]item4EachInfo, 4)
	high.EnduranceRun.IndexName = []string{"初一", "初二", "初三", "平均"}
	high.EnduranceRun.EachInfo = make([]item4EachInfo, 4)
	high.Grip.IndexName = []string{"初一", "初二", "初三", "平均"}
	high.Grip.EachInfo = make([]item4EachInfo, 4)
	high.ReactionSpeed.IndexName = []string{"初一", "初二", "初三", "平均"}
	high.ReactionSpeed.EachInfo = make([]item4EachInfo, 4)
	high.VerticalJump.IndexName = []string{"初一", "初二", "初三", "平均"}
	high.VerticalJump.EachInfo = make([]item4EachInfo, 4)
	high.BalanceAbility.IndexName = []string{"初一", "初二", "初三", "平均"}
	high.BalanceAbility.EachInfo = make([]item4EachInfo, 4)
	return nil
}

func (high *High) SeniorInit(school *entity.School, measurementDate time.Time) (err error) {
	high.SchoolInfo.Area, err = util.GetCityAreaName(school.ProvinceId, school.CityId, school.AreaId)
	if err != nil {
		return err
	}
	high.SchoolInfo.Name = school.Name
	high.SchoolInfo.SchoolType = 2
	high.SchoolInfo.Year = strconv.Itoa(measurementDate.Year())
	high.StudentNum.IndexName = []string{"高一", "高二", "高三"}
	high.StudentNum.EachInfo = make([]studentNumEachInfo, 3)
	high.SchoolScoresInfo.Boy = make([]float64, 4)
	high.SchoolScoresInfo.Girl = make([]float64, 4)
	high.SchoolScoresInfo.Avg = make([]float64, 4)
	high.Height.IndexName = []string{"高一", "高二", "高三"}
	high.Height.EachInfo = make([]item1EachInfo, 3)
	high.Weight.IndexName = []string{"高一", "高二", "高三"}
	high.Weight.EachInfo = make([]item1EachInfo, 3)
	high.BodyMassIndex.IndexName = []string{"高一", "高二", "高三", "平均"}
	high.BodyMassIndex.EachInfo = make([]item2EachInfo, 4)
	high.BodyFat.IndexName = []string{"高一", "高二", "高三", "平均"}
	high.BodyFat.EachInfo = make([]item3EachInfo, 4)
	high.VitalCapacity.IndexName = []string{"高一", "高二", "高三", "平均"}
	high.VitalCapacity.EachInfo = make([]item4EachInfo, 4)
	high.FiftyMeter.IndexName = []string{"高一", "高二", "高三", "平均"}
	high.FiftyMeter.EachInfo = make([]item4EachInfo, 4)
	high.SitAndReach.IndexName = []string{"高一", "高二", "高三", "平均"}
	high.SitAndReach.EachInfo = make([]item4EachInfo, 4)
	high.StandingLongJump.IndexName = []string{"高一", "高二", "高三", "平均"}
	high.StandingLongJump.EachInfo = make([]item4EachInfo, 4)
	high.OneMinuteSitUps.IndexName = []string{"高一", "高二", "高三", "平均"}
	high.OneMinuteSitUps.EachInfo = make([]item4EachInfo, 4)
	high.EnduranceRun.IndexName = []string{"高一", "高二", "高三", "平均"}
	high.EnduranceRun.EachInfo = make([]item4EachInfo, 4)
	high.Grip.IndexName = []string{"高一", "高二", "高三", "平均"}
	high.Grip.EachInfo = make([]item4EachInfo, 4)
	high.ReactionSpeed.IndexName = []string{"高一", "高二", "高三", "平均"}
	high.ReactionSpeed.EachInfo = make([]item4EachInfo, 4)
	high.VerticalJump.IndexName = []string{"高一", "高二", "高三", "平均"}
	high.VerticalJump.EachInfo = make([]item4EachInfo, 4)
	high.BalanceAbility.IndexName = []string{"高一", "高二", "高三", "平均"}
	high.BalanceAbility.EachInfo = make([]item4EachInfo, 4)
	return nil
}

type schoolInfo struct {
	Area         string  `json:"Area"`       //北京市 海淀区
	Name         string  `json:"Name"`       //洋房小学
	SchoolType   byte    `json:"SchoolType"` //1 1：小学 2：中学 3：高中
	Year         string  `json:"Year"`       //2018
	Score        float64 `json:"Score"`      //78.5
	Level        string  `json:"Level"`
	HasExtension bool    `json:"HasExtension"`
}

type studentNum struct {
	IndexName []string             `json:"IndexName"`
	EachInfo  []studentNumEachInfo `json:"EachInfo"`
}

type studentNumEachInfo struct {
	Boy           int64 `json:"Boy"`
	Girl          int64 `json:"Girl"`
	BoyAbsent     int64 `json:"BoyAbsent"`
	GirlAbsent    int64 `json:"GirlAbsent"`
	BoyPrivilege  int64 `json:"BoyPrivilege"`
	GirlPrivilege int64 `json:"GirlPrivilege"`
}

type eachScoreInfo struct {
	Total total `json:"Total"`
}

type total struct {
	BoyScore  float64 `json:"BoyScore"`
	GirlScore float64 `json:"GirlScore"`
	AvgScore  float64 `json:"AvgScore"`
}

type schoolScoresInfo struct {
	Boy  []float64 `json:"Boy"`
	Girl []float64 `json:"Girl"`
	Avg  []float64 `json:"Avg"`
}

type item1 struct {
	IndexName []string        `json:"IndexName"`
	EachInfo  []item1EachInfo `json:"EachInfo"`
}

type item1EachInfo struct {
	Boy  item1EachInfoDetail `json:"Boy"`
	Girl item1EachInfoDetail `json:"Girl"`
	Avg  item1EachInfoDetail `json:Avg`
}

type item1EachInfoDetail struct {
	Result float64 `json:"Result"`
}

type item2 struct {
	IndexName []string        `json:"IndexName"`
	EachInfo  []item2EachInfo `json:"EachInfo"`
}

type item2EachInfo struct {
	Boy  item2EachInfoDetail `json:"Boy"`
	Girl item2EachInfoDetail `json:"Girl"`
	Avg  item2EachInfoDetail `json:Avg`
}

type item2EachInfoDetail struct {
	Result     float64                       `json:"Result"`
	Score      float64                       `json:"Score"`
	Max        float64                       `json:"Max"`
	Min        float64                       `json:"Min"`
	Percentage item2EachInfoDetailPercentage `json:"Percentage"`
}

type item2EachInfoDetailPercentage struct {
	Failed    float64 `json:"Bujige"`
	Pass      float64 `json:"Jige"`
	Good      float64 `json:"Lianghao"`
	Excellent float64 `json:"Youxiu"`
	Qualified float64 `json:"Hege"`
}

type item3 struct {
	IndexName []string        `json:"IndexName"`
	EachInfo  []item3EachInfo `json:"EachInfo"`
}

type item3EachInfo struct {
	Boy  item3EachInfoDetail `json:"Boy"`
	Girl item3EachInfoDetail `json:"Girl"`
	Avg  item3EachInfoDetail `json:Avg`
}

type item3EachInfoDetail struct {
	Result      float64 `json:"Result"`
	Standard    float64 `json:"Biaozhun"`
	Excess      float64 `json:"Chaobiao"`
	LowStandard float64 `json:"Dibiao"`
}

type item4 struct {
	IndexName []string        `json:"IndexName"`
	EachInfo  []item4EachInfo `json:"EachInfo"`
}

type item4EachInfo struct {
	Boy  item4EachInfoDetail `json:"Boy"`
	Girl item4EachInfoDetail `json:"Girl"`
	Avg  item4EachInfoDetail `json:Avg`
}

type item4EachInfoDetail struct {
	Result     float64                       `json:"Result"`
	Score      float64                       `json:"Score"`
	Nums       item4EachInfoDetailNums       `json:"Nums"`
	Percentage item4EachInfoDetailPercentage `json:"Percentage"`
}

type item4EachInfoDetailNums struct {
	Failed    int64 `json:"Bujige"`
	Pass      int64 `json:"Jige"`
	Good      int64 `json:"Lianghao"`
	Excellent int64 `json:"Youxiu"`
	Qualified int64 `json:"Hege"`
}

type item4EachInfoDetailPercentage struct {
	Failed    float64 `json:"Bujige"`
	Pass      float64 `json:"Jige"`
	Good      float64 `json:"Lianghao"`
	Excellent float64 `json:"Youxiu"`
	Qualified float64 `json:"Hege"`
}
